﻿using System;
using System.Collections.Generic;
using Paulovich.Data;
using System.Collections.ObjectModel;
using System.Data;
using Paulovich.Data.SqlBuilder;

namespace Inscricoes.Business
{

    [Table("TCUR_Cursos")]
    public class Curso : Persist
    {

        #region fields & properties

        private int curCodigo;

        [PrimaryKeyField(IsIdentity = true)]
        public int CurCodigo
        {
            get { return curCodigo; }
            set { curCodigo = value; }
        }

        private string curNome;

        [Field]
        public string CurNome
        {
            get { return curNome; }
            set { curNome = value; }
        }

        private string curDescricao;

        [Field]
        public string CurDescricao
        {
            get { return curDescricao; }
            set { curDescricao = value; }
        }

        private int curLimiteInscricoes;

        [Field]
        public int CurLimiteInscricoes
        {
            get { return curLimiteInscricoes; }
            set { curLimiteInscricoes = value; }
        }

        private DateTime curDataInicio;

        [Field]
        public DateTime CurDataInicio
        {
            get { return curDataInicio; }
            set { curDataInicio = value; }
        }

        private DateTime curDataFim;

        [Field]
        public DateTime CurDataFim
        {
            get { return curDataFim; }
            set { curDataFim = value; }
        }

        private bool curStatus;

        [Field]
        public bool CurStatus
        {
            get { return curStatus; }
            set { curStatus = value; }
        }

        #endregion

        #region constructors

        public Curso()
            : base()
        {
        }

        public Curso(params object[] keys)
            : base(keys)
        {
        }

        #endregion

        #region related tables

        private Collection<Periodo> periodos;

        [ListToSave]
        public Collection<Periodo> Periodos
        {
            get { return periodos; }
            set { periodos = value; }
        }

        #endregion

        public static DataTable SelectOrderingByName()
        {

            try
            {

                var query = new SelectBuilder();

                query.Select.Add("CurCodigo, CurNome");
                query.TableName = "TCUR_Cursos";
                query.OrderBy = "CurNome";

                var command = new Command();

                command.CommandText = query.ToString();

                return (DataTable)command.ExecuteQuery(ReturnType.DataTable);

            }
            catch (Exception)
            {

                throw;
            }

        }


    }

}
